package cn.newgrand.netcall.smackx.integration;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;

public class AppSysOfflineDateIQ extends IQ{
	
	private String receiverJid;
	private long offlineDate;

	@Override
	public String getChildElementXML() {
		StringBuilder builder = new StringBuilder();
		builder.append("<query xmlns=\"ng:iq:appsysofflinedate\">");
		if(getReceiverJid() != null){
			builder.append("<receiverjid>").append(getReceiverJid()).append("</receiverjid>");
        }
		builder.append("</query>");
        return builder.toString();
	}

	public String getReceiverJid() {
		return receiverJid;
	}

	public void setReceiverJid(String receiverJid) {
		this.receiverJid = receiverJid;
	}

	public long getOfflineDate() {
		return offlineDate;
	}

	public void setOfflineDate(long offlineDate) {
		this.offlineDate = offlineDate;
	}
	
	public static class Provider implements IQProvider{

		@Override
		public IQ parseIQ(XmlPullParser parser) throws Exception {
			AppSysOfflineDateIQ offlineDateIQ = new AppSysOfflineDateIQ();
			boolean done = true;
			while(done){
				int eventType = parser.next();
				if(XmlPullParser.START_TAG == eventType){
					if("offlinedate".equals(parser.getName())){
						offlineDateIQ.setOfflineDate(Long.parseLong(parser.nextText()));
					}
				}else if(XmlPullParser.END_TAG == eventType){
					if("query".equals(parser.getName())){
						done = false;
					}
				}
			}
			return offlineDateIQ;
		}
		
	}

}
